package cn.ut.pc.one.xkb.service.impl;

import cn.ut.pc.one.xkb.dao.UserDao;
import cn.ut.pc.one.xkb.entity.User;
import cn.ut.pc.one.xkb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author xiongkaibin
 */
public class UserServiceImpl implements UserService {
    private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    @Autowired
    private UserDao userDao;

    @Override
    public User create(User user) {
        String hash = encoder.encode(user.getPassword());
        user.setPassword(hash);
        User u = userDao.save(user);
        return u;
    }
}
